﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Himp.Platform.Migrations
{
    /// <inheritdoc />
    public partial class modify_table_ : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_MainStdModelAssocPhrDict_MainStdModelConfig_StdModelConfigId",
                table: "MainStdModelAssocPhrDict");

            migrationBuilder.DropTable(
                name: "MainOpenApiConfig");

            migrationBuilder.DropTable(
                name: "MainStColumnConfig");

            migrationBuilder.DropTable(
                name: "MainStdModelConfig");

            migrationBuilder.DropTable(
                name: "SfConfig");

            migrationBuilder.DropTable(
                name: "MainStConfig");

            migrationBuilder.CreateTable(
                name: "MainStdApiConfig",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    TopicConfigId = table.Column<Guid>(type: "uuid", nullable: false),
                    OpenApiConfigCodg = table.Column<string>(type: "text", nullable: false),
                    OpenApiConfigName = table.Column<string>(type: "text", nullable: false),
                    SrtNo = table.Column<int>(type: "integer", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    ExtraProperties = table.Column<string>(type: "text", nullable: false),
                    ConcurrencyStamp = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: false),
                    CreationTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uuid", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uuid", nullable: true),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uuid", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainStdApiConfig", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainStdApiConfig_MainTopicConfig_TopicConfigId",
                        column: x => x.TopicConfigId,
                        principalTable: "MainTopicConfig",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "MainStdModelDict",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    ModelCode = table.Column<string>(type: "text", nullable: false),
                    ModelName = table.Column<string>(type: "text", nullable: false),
                    ModelType = table.Column<int>(type: "integer", nullable: false),
                    TopicConfigId = table.Column<Guid>(type: "uuid", nullable: false),
                    Exp = table.Column<string>(type: "text", nullable: true),
                    Ver = table.Column<int>(type: "integer", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainStdModelDict", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainStdModelDict_MainTopicConfig_TopicConfigId",
                        column: x => x.TopicConfigId,
                        principalTable: "MainTopicConfig",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "StdFormDict",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    ProjectConfigId = table.Column<Guid>(type: "uuid", nullable: false),
                    SfCodg = table.Column<string>(type: "text", nullable: false),
                    SfName = table.Column<string>(type: "text", nullable: false),
                    SchemaJson = table.Column<string>(type: "text", nullable: false),
                    DefaultFlag = table.Column<bool>(type: "boolean", nullable: false),
                    OpenApiConfigId = table.Column<Guid>(type: "uuid", nullable: true),
                    Ver = table.Column<int>(type: "integer", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_StdFormDict", x => x.Id);
                    table.ForeignKey(
                        name: "FK_StdFormDict_MainTopicConfig_ProjectConfigId",
                        column: x => x.ProjectConfigId,
                        principalTable: "MainTopicConfig",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "MainStdTableDict",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    TopicConfigId = table.Column<Guid>(type: "uuid", nullable: false),
                    StdTableCode = table.Column<string>(type: "text", nullable: false),
                    StdTableName = table.Column<string>(type: "text", nullable: false),
                    Descr = table.Column<string>(type: "text", nullable: true),
                    StdApiConfigId = table.Column<Guid>(type: "uuid", nullable: true),
                    DefaultFlag = table.Column<bool>(type: "boolean", nullable: false),
                    Ver = table.Column<int>(type: "integer", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainStdTableDict", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainStdTableDict_MainStdApiConfig_StdApiConfigId",
                        column: x => x.StdApiConfigId,
                        principalTable: "MainStdApiConfig",
                        principalColumn: "Id");
                    table.ForeignKey(
                        name: "FK_MainStdTableDict_MainTopicConfig_TopicConfigId",
                        column: x => x.TopicConfigId,
                        principalTable: "MainTopicConfig",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "MainStdTableColumnConfig",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    StConfigId = table.Column<Guid>(type: "uuid", nullable: false),
                    HeaderName = table.Column<string>(type: "text", nullable: false),
                    Field = table.Column<string>(type: "text", nullable: false),
                    Type = table.Column<string>(type: "text", nullable: false),
                    Srtno = table.Column<int>(type: "integer", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainStdTableColumnConfig", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainStdTableColumnConfig_MainStdTableDict_StConfigId",
                        column: x => x.StConfigId,
                        principalTable: "MainStdTableDict",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_MainStdApiConfig_TopicConfigId",
                table: "MainStdApiConfig",
                column: "TopicConfigId");

            migrationBuilder.CreateIndex(
                name: "IX_MainStdModelDict_TopicConfigId",
                table: "MainStdModelDict",
                column: "TopicConfigId");

            migrationBuilder.CreateIndex(
                name: "IX_MainStdTableColumnConfig_StConfigId",
                table: "MainStdTableColumnConfig",
                column: "StConfigId");

            migrationBuilder.CreateIndex(
                name: "IX_MainStdTableDict_StdApiConfigId",
                table: "MainStdTableDict",
                column: "StdApiConfigId");

            migrationBuilder.CreateIndex(
                name: "IX_MainStdTableDict_TopicConfigId",
                table: "MainStdTableDict",
                column: "TopicConfigId");

            migrationBuilder.CreateIndex(
                name: "IX_StdFormDict_ProjectConfigId",
                table: "StdFormDict",
                column: "ProjectConfigId");

            migrationBuilder.AddForeignKey(
                name: "FK_MainStdModelAssocPhrDict_MainStdModelDict_StdModelConfigId",
                table: "MainStdModelAssocPhrDict",
                column: "StdModelConfigId",
                principalTable: "MainStdModelDict",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_MainStdModelAssocPhrDict_MainStdModelDict_StdModelConfigId",
                table: "MainStdModelAssocPhrDict");

            migrationBuilder.DropTable(
                name: "MainStdModelDict");

            migrationBuilder.DropTable(
                name: "MainStdTableColumnConfig");

            migrationBuilder.DropTable(
                name: "StdFormDict");

            migrationBuilder.DropTable(
                name: "MainStdTableDict");

            migrationBuilder.DropTable(
                name: "MainStdApiConfig");

            migrationBuilder.CreateTable(
                name: "MainOpenApiConfig",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    TopicConfigId = table.Column<Guid>(type: "uuid", nullable: false),
                    ConcurrencyStamp = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: false),
                    CreationTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uuid", nullable: true),
                    DeleterId = table.Column<Guid>(type: "uuid", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
                    ExtraProperties = table.Column<string>(type: "text", nullable: false),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uuid", nullable: true),
                    OpenApiConfigCodg = table.Column<string>(type: "text", nullable: false),
                    OpenApiConfigName = table.Column<string>(type: "text", nullable: false),
                    SrtNo = table.Column<int>(type: "integer", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainOpenApiConfig", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainOpenApiConfig_MainTopicConfig_TopicConfigId",
                        column: x => x.TopicConfigId,
                        principalTable: "MainTopicConfig",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "MainStConfig",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    ProjectConfigId = table.Column<Guid>(type: "uuid", nullable: false),
                    Contdesc = table.Column<string>(type: "text", nullable: true),
                    DefaultFlag = table.Column<bool>(type: "boolean", nullable: false),
                    OpenApiConfigId = table.Column<Guid>(type: "uuid", nullable: true),
                    StCodg = table.Column<string>(type: "text", nullable: false),
                    StName = table.Column<string>(type: "text", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    Ver = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainStConfig", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainStConfig_MainTopicConfig_ProjectConfigId",
                        column: x => x.ProjectConfigId,
                        principalTable: "MainTopicConfig",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "MainStdModelConfig",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    TopicConfigId = table.Column<Guid>(type: "uuid", nullable: false),
                    Exp = table.Column<string>(type: "text", nullable: true),
                    ModelCode = table.Column<string>(type: "text", nullable: false),
                    ModelName = table.Column<string>(type: "text", nullable: false),
                    ModelType = table.Column<int>(type: "integer", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    Ver = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainStdModelConfig", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainStdModelConfig_MainTopicConfig_TopicConfigId",
                        column: x => x.TopicConfigId,
                        principalTable: "MainTopicConfig",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "SfConfig",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    ProjectConfigId = table.Column<Guid>(type: "uuid", nullable: false),
                    DefaultFlag = table.Column<bool>(type: "boolean", nullable: false),
                    OpenApiConfigId = table.Column<Guid>(type: "uuid", nullable: true),
                    SchemaJson = table.Column<string>(type: "text", nullable: false),
                    SfCodg = table.Column<string>(type: "text", nullable: false),
                    SfName = table.Column<string>(type: "text", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    Ver = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SfConfig", x => x.Id);
                    table.ForeignKey(
                        name: "FK_SfConfig_MainTopicConfig_ProjectConfigId",
                        column: x => x.ProjectConfigId,
                        principalTable: "MainTopicConfig",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "MainStColumnConfig",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    StConfigId = table.Column<Guid>(type: "uuid", nullable: false),
                    Field = table.Column<string>(type: "text", nullable: false),
                    HeaderName = table.Column<string>(type: "text", nullable: false),
                    Srtno = table.Column<int>(type: "integer", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    Type = table.Column<string>(type: "text", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainStColumnConfig", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainStColumnConfig_MainStConfig_StConfigId",
                        column: x => x.StConfigId,
                        principalTable: "MainStConfig",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_MainOpenApiConfig_TopicConfigId",
                table: "MainOpenApiConfig",
                column: "TopicConfigId");

            migrationBuilder.CreateIndex(
                name: "IX_MainStColumnConfig_StConfigId",
                table: "MainStColumnConfig",
                column: "StConfigId");

            migrationBuilder.CreateIndex(
                name: "IX_MainStConfig_ProjectConfigId",
                table: "MainStConfig",
                column: "ProjectConfigId");

            migrationBuilder.CreateIndex(
                name: "IX_MainStdModelConfig_TopicConfigId",
                table: "MainStdModelConfig",
                column: "TopicConfigId");

            migrationBuilder.CreateIndex(
                name: "IX_SfConfig_ProjectConfigId",
                table: "SfConfig",
                column: "ProjectConfigId");

            migrationBuilder.AddForeignKey(
                name: "FK_MainStdModelAssocPhrDict_MainStdModelConfig_StdModelConfigId",
                table: "MainStdModelAssocPhrDict",
                column: "StdModelConfigId",
                principalTable: "MainStdModelConfig",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }
    }
}
